Skip to content

chore(backend): harden sqlite concurrent writes and add stress tests#10

Merged
hammond01 merged 2 commits into
devfrom
chore/backend-hardening-tests
May 25, 2026
Merged

chore(backend): harden sqlite concurrent writes and add stress tests#10
hammond01 merged 2 commits into
devfrom
chore/backend-hardening-tests

Conversation

@hammond01
Copy link
Copy Markdown
Owner

Summary

  • replace fragile MAX(row_id)+1 flow with safer insert/upsert + rowid backfill in SQLite repositories
  • add lock-aware retry with short backoff for SQLite lock/busy contention during writes
  • make activity log writes idempotent via ON CONFLICT(id) DO UPDATE
  • expand SQLite repository integration tests with concurrent insert stress coverage for captures, items, and activity logs

Why

SQLite shared-cache writes can transiently fail under concurrent writes (SQLITE_LOCKED_SHAREDCACHE). This PR improves resilience and ensures row id assignment remains stable under load.

Validation

  • backend tests: ./gradlew test

Copilot AI review requested due to automatic review settings May 22, 2026 09:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@hammond01 hammond01 marked this pull request as ready for review May 25, 2026 03:42
Copilot AI review requested due to automatic review settings May 25, 2026 03:42
@hammond01 hammond01 merged commit fbbcb3e into dev May 25, 2026
3 checks passed
@hammond01 hammond01 deleted the chore/backend-hardening-tests branch May 25, 2026 03:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Comment on lines +46 to +54
// @Autowired
// private JdbcTemplate jdbcTemplate;

@BeforeEach
void cleanTables() {
jdbcTemplate.update("DELETE FROM activity_logs");
jdbcTemplate.update("DELETE FROM items");
jdbcTemplate.update("DELETE FROM captures");
}
// @BeforeEach
// void cleanTables() {
// jdbcTemplate.update("DELETE FROM activity_logs");
// jdbcTemplate.update("DELETE FROM items");
// jdbcTemplate.update("DELETE FROM captures");
// }
Comment on lines +94 to +95
jdbcTemplate.update(BACKFILL_ROW_ID_SQL, normalizedCapture.id());
Long persistedRowId = jdbcTemplate.queryForObject(FIND_ROW_ID_BY_ID_SQL, Long.class, normalizedCapture.id());
Comment on lines +165 to +170
private boolean isSqliteLocked(Throwable throwable) {
Throwable current = throwable;
while (current != null) {
String message = current.getMessage();
String className = current.getClass().getName();
boolean sqliteCause = className.contains("SQLite");
if (!isSqliteLocked(exception) || attempt == SQLITE_LOCK_RETRY_MAX - 1) {
throw exception;
}
sleepBackoff(attempt);
normalizedCapture.deletedAt()
);
return normalizedCapture;
return withSqliteLockRetry(() -> {
Comment on lines +94 to +95
jdbcTemplate.update(BACKFILL_ROW_ID_SQL, normalizedCapture.id());
Long persistedRowId = jdbcTemplate.queryForObject(FIND_ROW_ID_BY_ID_SQL, Long.class, normalizedCapture.id());
Comment thread README.md
# macOS / Linux
./gradlew bootRun
# Windows (PowerShell / CMD)
.\\gradlew.bat bootRun
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants